package com.fcl.oschina.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.fcl.mylibrary.ImageLoader.ImageLoader;
import com.fcl.mylibrary.reflect.ViewInject;
import com.fcl.mylibrary.ui.adapter.MainTabAdapter;
import com.fcl.oschina.R;
import com.fcl.oschina.entity.UserEntity;
import com.fcl.oschina.model.UserInfoModel;
import com.fcl.oschina.ui.fragment.BlogFragment;
import com.fcl.oschina.ui.fragment.TestFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class UserInfoActivity extends BaseBackActivity implements UserInfoView{

    private int mId;
    private UserInfoModel mUserInfoModel;

    @ViewInject(R.id.user_avtar)
    CircleImageView mUserAvtar;

    @ViewInject(R.id.tool_user_avtar)
    CircleImageView mToolUserAvtar;

    @ViewInject(R.id.user_name)
    TextView mUserTv;

    @ViewInject(R.id.tool_user_name)
    TextView mToolUserTv;

    @ViewInject(R.id.desc)
    TextView mDescTv;

    @ViewInject(R.id.score)
    TextView mScoreTv;

    @ViewInject(R.id.tab_layout)
    TabLayout mTabLayout;

    @ViewInject(R.id.pager)
    ViewPager mPager;

    private List<String> mTitles = new ArrayList<>();
    private List<Fragment> mFragments = new ArrayList<>();
    private MainTabAdapter mMainTabAdapter;
    private BlogFragment mBlogFragment;

    @Override
    protected void init() {
        super.init();
        mId = getIntent().getIntExtra("id", 0);
        mUserInfoModel = new UserInfoModel(this);
        mUserInfoModel.getUserInfo(mId);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_user_info;
    }

    @Override
    public void setInfo(UserEntity data) {
        mUserTv.setText(data.getName());
        mToolUserTv.setText(data.getName());
        ImageLoader.getInstance().loadImage(data.getPortrait(), mUserAvtar, true);
        ImageLoader.getInstance().loadImage(data.getPortrait(), mToolUserAvtar, true);
        mDescTv.setText(data.getDesc());
        mScoreTv.setText("积分:"+data.getStatistics().getScore());

        mTitles.clear();
        mTitles.add(data.getStatistics().getTweet()+"\n动弹");
        mTitles.add(data.getStatistics().getBlog()+"\n博客");
        mTitles.add(data.getStatistics().getAnswer()+"\n问答");
        mTitles.add(data.getStatistics().getDiscuss()+"\n讨论");
        mFragments.clear();
        mFragments.add(new TestFragment());
        mBlogFragment = new BlogFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type", BlogFragment.USER);
        bundle.putInt("author_id", data.getId());
        mBlogFragment.setArguments(bundle);
        mFragments.add(mBlogFragment);
        mFragments.add(new TestFragment());
        mFragments.add(new TestFragment());
        mMainTabAdapter = new MainTabAdapter(getSupportFragmentManager(),this,mFragments,mTitles);
        mPager.setAdapter(mMainTabAdapter);
        mTabLayout.setupWithViewPager(mPager);
        mTabLayout.setTabTextColors(getResources().getColor(R.color.colorSecondaryText),
                getResources().getColor(R.color.white));
        mTabLayout.setSelectedTabIndicatorColor(Color.WHITE);
    }
}
